package org.yelongframework.excel.data.collect.excel;

import java.util.List;
import java.util.Objects;

import org.yelongframework.excel.data.ExcelDatas;
import org.yelongframework.excel.data.SheetDatas;
import org.yelongframework.excel.data.collect.sheet.SheetDataCollectMode;
import org.yelongframework.excel.data.collect.sheet.SheetDataCollector;
import org.yelongframework.excel.data.collect.sheet.manager.SheetDataCollectorManager;
import org.yelongframework.excel.data.collect.sheet.mode.all.AllSheetDataCollectScheme;
import org.yelongframework.excel.sheet.ExcelSheet;
import org.yelongframework.excel.workbook.ExcelWorkbook;

/**
 * 默认实现
 * 
 * @since 1.0.0
 */
public class DefaultExcelDataCollector implements ExcelDataCollector {

	/** 工作表数据收集管理器 */
	private final SheetDataCollectorManager sheetDataCollectorManager;

	// ==================================================构造器==================================================

	/**
	 * @param sheetDataCollectorManager 工作表数据收集管理器
	 */
	public DefaultExcelDataCollector(SheetDataCollectorManager sheetDataCollectorManager) {
		this.sheetDataCollectorManager = Objects.requireNonNull(sheetDataCollectorManager, "sheetDataCollectorManager");
	}

	// ==================================================工作薄==================================================

	@Override
	public ExcelDatas collect(ExcelWorkbook workbook) {
		SheetDataCollector sheetDataCollector = sheetDataCollectorManager
				.getSheetDataCollector(SheetDataCollectMode.ALL);
		ExcelDatas excelDatas = new ExcelDatas();
		List<ExcelSheet> sheetList = workbook.getSheetList();
		for (ExcelSheet excelSheet : sheetList) {
			SheetDatas sheetDatas = sheetDataCollector.collect(excelSheet, AllSheetDataCollectScheme.INSTANCE);
			excelDatas.add(sheetDatas);
		}
		return excelDatas;
	}

	// ==================================================工作表数据收集器管理器==================================================

	@Override
	public SheetDataCollectorManager getSheetDataCollectorManager() {
		return sheetDataCollectorManager;
	}

}
